<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>6.270 - JoyOS: lib/motion.h File Reference</title>
	<link href="main.css" media="screen" rel="Stylesheet" type="text/css"/>
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>  
<body>
	<div id="header">
		<div id="headerb">
		<div id="headtext">
			<span class="titletext">AUTONOMOUS ROBOT DESIGN COMPETITION</span>
			6.270
		</div>
		<div class="mainmenu">
			<a href="http://web.mit.edu/6.270/www">Home</a>
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/about/">About</a> 
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/sponsors/">Sponsors</a>
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/contests/">Past Contests</a> 
		 	&bull;
			<a href="http://web.mit.edu/6.270/www/contestants/">Contestant Information</a>
		</div>
	</div>
	</div>

<div class="maincontent">
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>lib/motion.h File Reference</h1>A PID-controlled MotorGroup. <a href="#_details">More...</a>
<p>
<code>#include &lt;<a class="el" href="global_8h.html">kern/global.h</a>&gt;</code><br>
<code>#include &lt;<a class="el" href="motor__group_8h.html">lib/motor_group.h</a>&gt;</code><br>
<code>#include &lt;<a class="el" href="pid_8h.html">lib/pid.h</a>&gt;</code><br>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Data Structures</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">struct &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="struct_motion_controller.html">MotionController</a></td></tr>

<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="motion_8h.html#81540e9096fa135a6960136fa78bf5fb">motion_init</a> (<a class="el" href="struct_motion_controller.html">MotionController</a> *motion, <a class="el" href="motor__group_8h.html#bf80c97904f3c321e634674c7a1d8002">MotorGroup</a> motor, uint8_t encoder_port, float kp, float ki, float kd)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="motion_8h.html#a892325016f2ede133535e6a1ec33bd4">motion_set_goal</a> (<a class="el" href="struct_motion_controller.html">MotionController</a> *motion, int32_t goal)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="motion_8h.html#4894c14aa7184b01b4b5e2d4d9a7660a">motion_update</a> (<a class="el" href="struct_motion_controller.html">MotionController</a> *motion)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="motion_8h.html#b9d3563ef588fb49fb27a460072ed215">motion_goal_reached</a> (<a class="el" href="struct_motion_controller.html">MotionController</a> *motion)</td></tr>

</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
A <a class="el" href="struct_motion_controller.html">MotionController</a> provides a PID-controlled MotorGroup.<p>
Given a MotorGroup (one or more motors), an encoder port and a target position, the <a class="el" href="struct_motion_controller.html">MotionController</a> will attempt to drive the MotorGroup to the given target. <hr><h2>Function Documentation</h2>
<a class="anchor" name="b9d3563ef588fb49fb27a460072ed215"></a><!-- doxytag: member="motion.h::motion_goal_reached" ref="b9d3563ef588fb49fb27a460072ed215" args="(MotionController *motion)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool motion_goal_reached           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_motion_controller.html">MotionController</a> *&nbsp;</td>
          <td class="paramname"> <em>motion</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Check if the MotionController's goal has been reached<p>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>true if goal reached, false otherwise </dd></dl>

</div>
</div><p>
<a class="anchor" name="81540e9096fa135a6960136fa78bf5fb"></a><!-- doxytag: member="motion.h::motion_init" ref="81540e9096fa135a6960136fa78bf5fb" args="(MotionController *motion, MotorGroup motor, uint8_t encoder_port, float kp, float ki, float kd)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void motion_init           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_motion_controller.html">MotionController</a> *&nbsp;</td>
          <td class="paramname"> <em>motion</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="motor__group_8h.html#bf80c97904f3c321e634674c7a1d8002">MotorGroup</a>&nbsp;</td>
          <td class="paramname"> <em>motor</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint8_t&nbsp;</td>
          <td class="paramname"> <em>encoder_port</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">float&nbsp;</td>
          <td class="paramname"> <em>kp</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">float&nbsp;</td>
          <td class="paramname"> <em>ki</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">float&nbsp;</td>
          <td class="paramname"> <em>kd</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Create a new <a class="el" href="struct_motion_controller.html">MotionController</a><p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>motion</em>&nbsp;</td><td><a class="el" href="struct_motion_controller.html">MotionController</a> to initialise </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>motor</em>&nbsp;</td><td>MotorGroup to drive </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>encoder_port</em>&nbsp;</td><td>Encoder port to read motor position from </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>kp</em>&nbsp;</td><td>Proportional constant for PID </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>ki</em>&nbsp;</td><td>Integral constant for PID </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>kd</em>&nbsp;</td><td>Derivative constant for PID </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="a892325016f2ede133535e6a1ec33bd4"></a><!-- doxytag: member="motion.h::motion_set_goal" ref="a892325016f2ede133535e6a1ec33bd4" args="(MotionController *motion, int32_t goal)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void motion_set_goal           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_motion_controller.html">MotionController</a> *&nbsp;</td>
          <td class="paramname"> <em>motion</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int32_t&nbsp;</td>
          <td class="paramname"> <em>goal</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Set the target position for the <a class="el" href="struct_motion_controller.html">MotionController</a>. The controller will immediately start driving the motor towards the goal.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>motion</em>&nbsp;</td><td><a class="el" href="struct_motion_controller.html">MotionController</a> to set </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>goal</em>&nbsp;</td><td>Goal position to drive towards </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="4894c14aa7184b01b4b5e2d4d9a7660a"></a><!-- doxytag: member="motion.h::motion_update" ref="4894c14aa7184b01b4b5e2d4d9a7660a" args="(MotionController *motion)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void motion_update           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_motion_controller.html">MotionController</a> *&nbsp;</td>
          <td class="paramname"> <em>motion</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Perform one cycle of the motion controller loop. Call as often as possible.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>motion</em>&nbsp;</td><td><a class="el" href="struct_motion_controller.html">MotionController</a> to run </td></tr>
  </table>
</dl>

</div>
</div><p>
</div>
</div>
<div class="maincontent">
	<div class="footer centre">
		<hr>
		Generated on Sun Jan 18 22:59:34 2009 by&nbsp;<a href="http://www.doxygen.org/index.html">Doxygen</a> 1.5.6<br/>
		6.270 Staff, 2008 | 
		<a href="mailto:6.270-organizers@mit.edu">Contact Us</a> | 
		<a href="http://web.mit.edu">MIT</a>
	</div>
</div>
</body>
</html>
